package com.situ.day23.db;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.Properties;

public class DBTest {
    public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        //MySql mySql = new MySql();
        //mySql.getConnection();
        //IDB db = new MySql();
        //db.getConnection();
        //db = new Oracle();
        //db.getConnection();
        //只出现接口，不出现具体实现类，面向接口编程
        //反射+配置文件

        ClassLoader classLoader = DBTest.class.getClassLoader();
        InputStream inputStream = classLoader.getResourceAsStream("db1.properties");
        Properties properties = new Properties();
        properties.load(inputStream);
        String className = properties.getProperty("className");
        //com.situ.day23.db.SqlServer
        Class clazz = Class.forName(className);
        //Constructor constructor = clazz.getConstructor();
        //IDB db = (IDB) constructor.newInstance();

        //如果是new无参构造方法，可以直接clazz.newInstance()
        IDB db = (IDB) clazz.newInstance();
        db.getConnection();
    }
}
